<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cardinal Quintic B-spline interpolation</title>
<link rel="stylesheet" href="../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Math Toolkit 4.2.0">
<link rel="up" href="../interpolation.html" title="Chapter 13. Interpolation">
<link rel="prev" href="cardinal_quadratic_b.html" title="Cardinal Quadratic B-spline interpolation">
<link rel="next" href="whittaker_shannon.html" title="Whittaker-Shannon interpolation">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cardinal_quadratic_b.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interpolation.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="whittaker_shannon.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="math_toolkit.cardinal_quintic_b"></a><a class="link" href="cardinal_quintic_b.html" title="Cardinal Quintic B-spline interpolation">Cardinal Quintic B-spline
    interpolation</a>
</h2></div></div></div>
<h4>
<a name="math_toolkit.cardinal_quintic_b.h0"></a>
      <span class="phrase"><a name="math_toolkit.cardinal_quintic_b.synopsis"></a></span><a class="link" href="cardinal_quintic_b.html#math_toolkit.cardinal_quintic_b.synopsis">Synopsis</a>
    </h4>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">interpolators</span><span class="special">/</span><span class="identifier">cardinal_quintic_b_spline</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">interpolators</span> <span class="special">{</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Real</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">cardinal_quintic_b_spline</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
    <span class="comment">// If you don't know the value of the derivative at the endpoints, leave them as NaNs and the routine will estimate them.</span>
    <span class="comment">// y[0] = y(a), y[n - 1] = y(b), step_size = (b - a)/(n -1).</span>
    <span class="identifier">cardinal_quintic_b_spline</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Real</span><span class="special">*</span> <span class="keyword">const</span> <span class="identifier">y</span><span class="special">,</span>
                              <span class="identifier">size_t</span> <span class="identifier">n</span><span class="special">,</span>
                              <span class="identifier">Real</span> <span class="identifier">t0</span> <span class="comment">/* initial time, left endpoint */</span><span class="special">,</span>
                              <span class="identifier">Real</span> <span class="identifier">h</span>  <span class="comment">/*spacing, stepsize*/</span><span class="special">,</span>
                              <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">,</span> <span class="identifier">Real</span><span class="special">&gt;</span> <span class="identifier">left_endpoint_derivatives</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">(),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limit</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">()},</span>
                              <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">,</span> <span class="identifier">Real</span><span class="special">&gt;</span> <span class="identifier">right_endpoint_derivatives</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">(),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limit</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">()})</span>

    <span class="identifier">cardinal_quintic_b_spline</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span>
                              <span class="identifier">Real</span> <span class="identifier">t0</span> <span class="comment">/* initial time, left endpoint */</span><span class="special">,</span>
                              <span class="identifier">Real</span> <span class="identifier">h</span>  <span class="comment">/*spacing, stepsize*/</span><span class="special">,</span>
                              <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">,</span> <span class="identifier">Real</span><span class="special">&gt;</span> <span class="identifier">left_endpoint_derivatives</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">(),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limit</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">()},</span>
                              <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">,</span> <span class="identifier">Real</span><span class="special">&gt;</span> <span class="identifier">right_endpoint_derivatives</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">(),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limit</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">()})</span>

    <span class="identifier">Real</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

    <span class="identifier">Real</span> <span class="identifier">prime</span><span class="special">(</span><span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

    <span class="identifier">Real</span> <span class="identifier">double_prime</span><span class="special">(</span><span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

<span class="special">};</span>
<span class="special">}}}</span>
</pre>
<h4>
<a name="math_toolkit.cardinal_quintic_b.h1"></a>
      <span class="phrase"><a name="math_toolkit.cardinal_quintic_b.cardinal_quintic_b_spline_interp"></a></span><a class="link" href="cardinal_quintic_b.html#math_toolkit.cardinal_quintic_b.cardinal_quintic_b_spline_interp">Cardinal
      Quintic B-Spline Interpolation</a>
    </h4>
<p>
      The cardinal quintic B-spline interpolator is very nearly the same as the cubic
      B-spline interpolator, with the modification that the basis functions are constructed
      by convolving a box function with itself five times, rather than three times
      as is done with the cubic B-spline.
    </p>
<p>
      The basis functions of the quintic B-spline interpolator are more smooth than
      the cubic <span class="emphasis"><em>B</em></span>-spline interpolator, and hence this is very
      useful for computing second derivatives. For example, the second derivative
      of the cubic spline interpolator is a piecewise linear function, whereas the
      second derivative of the quintic <span class="emphasis"><em>B</em></span>-spline is a cubic spline.
      The graph of the second derivative of the quintic <span class="emphasis"><em>B</em></span>-spline
      is therefore more visually appealing, though whether it is in fact more accurate
      depends on the smoothness of your data.
    </p>
<p>
      And example usage is as follows:
    </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">interpolators</span><span class="special">/</span><span class="identifier">cardinal_quintic_b_spline</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">interpolators</span><span class="special">::</span><span class="identifier">cardinal_quintic_b_spline</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">(</span><span class="number">512</span><span class="special">);</span>
<span class="comment">// fill v with data . . .</span>
<span class="keyword">double</span> <span class="identifier">t0</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="comment">// initial time</span>
<span class="keyword">double</span> <span class="identifier">h</span> <span class="special">=</span> <span class="number">0.125</span><span class="special">;</span> <span class="comment">// spacing</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">left_endpoint_derivatives</span><span class="special">{</span><span class="identifier">first_derivative_at_t0</span><span class="special">,</span> <span class="identifier">second_derivative_at_t0</span><span class="special">};</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">right_endpoint_derivatives</span><span class="special">{</span><span class="identifier">first_derivative_at_tf</span><span class="special">,</span> <span class="identifier">second_derivative_at_tf</span><span class="special">};</span>
<span class="keyword">auto</span> <span class="identifier">qs</span> <span class="special">=</span> <span class="identifier">cardinal_quintic_b_spline</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">t0</span><span class="special">,</span> <span class="identifier">h</span><span class="special">,</span> <span class="identifier">left_endpoint_derivatives</span><span class="special">,</span> <span class="identifier">right_endpoint_derivatives</span><span class="special">);</span>

<span class="comment">// Evaluate the interpolant at a point:</span>
<span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">qs</span><span class="special">(</span><span class="number">0.1</span><span class="special">);</span>
<span class="comment">// Evaluate the derivative of the interpolant:</span>
<span class="keyword">double</span> <span class="identifier">yp</span> <span class="special">=</span> <span class="identifier">qs</span><span class="special">.</span><span class="identifier">prime</span><span class="special">(</span><span class="number">0.1</span><span class="special">);</span>
<span class="comment">// Evaluate the second derivative of the interpolant:</span>
<span class="keyword">double</span> <span class="identifier">ypp</span> <span class="special">=</span> <span class="identifier">qs</span><span class="special">.</span><span class="identifier">double_prime</span><span class="special">(</span><span class="number">0.1</span><span class="special">);</span>
</pre>
<p>
      This routine will estimate the endpoint derivatives if they are not provided.
      <span class="emphasis"><em>Try to avoid this if possible.</em></span> The endpoint derivatives
      must be evaluated by finite differences and this is not robust again perturbations
      in the data. So if you have some way of knowing the endpoint derivatives, make
      sure to provide them.
    </p>
<h4>
<a name="math_toolkit.cardinal_quintic_b.h2"></a>
      <span class="phrase"><a name="math_toolkit.cardinal_quintic_b.references"></a></span><a class="link" href="cardinal_quintic_b.html#math_toolkit.cardinal_quintic_b.references">References</a>
    </h4>
<p>
      Cox, Maurice G. <span class="emphasis"><em>Numerical methods for the interpolation and approximation
      of data by spline functions.</em></span> Diss. City, University of London, 1975.
    </p>
</div>
<div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cardinal_quadratic_b.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interpolation.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="whittaker_shannon.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
